from .handler_base import HandlerBase
import platform
from app.utils.config_loader import app_config

class PowerOnHandler(HandlerBase):
    def handle(self, command):
        # 处理 power_on 指令
        print("执行 power_on 指令")

        # 获取 CMD 设备的串口端口
        os_type = "windows" if platform.system() == "Windows" else "linux"
        cmd_port = app_config.get(f"serial_ports.{os_type}.CMD")

        # 向 CMD 设备发送数据
        if self.serial_manager.send_data(cmd_port, "POWER_ON"):
            print("成功发送 POWER_ON 指令到 CMD 设备")
        else:
            print("发送 POWER_ON 指令到 CMD 设备失败")

        return self.build_response("power_on", is_set_power=1, is_set_timing=0, is_ignore_locktime=0)